<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>

    <link rel="stylesheet" type="text/css" href="../public/stylesheets/reset.css" />
    <link rel="stylesheet" type="text/css" href="../public/stylesheets/login.css" />
</head>

<body>
    <div class="pos">
        <div class="login">
            <span class="close iconfont icon-close"></span>
            <img src="../public/images/login/loginlogo.png" alt="">
            <ul>
                <li></li>
                <li class="phone">使用手机号登陆</li>
                <li></li>
            </ul>

            <input style="margin-top: 0;" type="text" name="tel" class="tel" id="username" placeholder="请输入您的手机号">
            <input type="password" name="pass" class="pass" id="password" placeholder="请输入密码">
            <span id="tips"></span>
            <button class="loginbtn">
                登陆
            </button>

            <p>
                <span>
                    还没有账号?
                    <a href="javascript:;">点击注册</a>
                </span>
            </p>
        </div>
    </div>

    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="../routes/myajax.js"></script>

    <script>
        $('button').click(async function () {
            // 获取输入框数据
            let username = $('#username').val();
            let password = $('#password').val();
            console.log(username, password);
            // ajax请求
            let [err, result] = await myajax({
                type: 'post',
                url: 'http://localhost:3000/login',
                data: { username, password }
            })

            if (err) {
                alert('请稍后再试');
                return;
            }

            if (result.code == 400) { //没有注册成功
                $('#tips').html(result.msg)
            } else {
                location.href = '../views/index.html'
            }
        })
    </script>

</body>

</html>